#pragma once

#include "UMLDiagram.h"

#include "../dc/Bounds.h"
#include "UMLLabel.h"

namespace uml {

const bool UMLDiagram::isFrame_default_ = true;
const bool UMLDiagram::isIso_default_ = true;
const bool UMLDiagram::isInheritedLighter_default_ = false;
const QString UMLDiagram::name_default_;
const QString UMLDiagram::documentation_default_;
const double UMLDiagram::resolution_default_ = 300;
UMLDiagram::UMLDiagram(const QString& umlType)
    : UMLDiagramElement(umlType) {}

void UMLDiagram::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    UMLDiagramElement::fromJson(json, errorList);
    isFrame_ = json.value("isFrame").toBool(isFrame_default_);
    isIso_ = json.value("isIso").toBool(isIso_default_);
    heading_ = JsonSerializable::create<UMLLabel>(json.value("heading"), errorList);

    isInheritedLighter_ = json.value("isInheritedLighter").toBool(isInheritedLighter_default_);
    name_ = json.value("name").toString(name_default_);
    documentation_ = json.value("documentation").toString(documentation_default_);
    resolution_ = json.value("resolution").toDouble(resolution_default_);
    bounds_ = JsonSerializable::create<Bounds>(json.value("bounds"), errorList);

}

void UMLDiagram::toJson(QJsonObject& json) {
    UMLDiagramElement::toJson(json);
    if (isFrame_ != isFrame_default_) {
        json.insert("isFrame", isFrame_);
    }
    if (isIso_ != isIso_default_) {
        json.insert("isIso", isIso_);
    }
    if (heading_) {
        QJsonObject heading_json;
        heading_->toJson(heading_json);
        json.insert("heading", heading_json);
    }
    if (isInheritedLighter_ != isInheritedLighter_default_) {
        json.insert("isInheritedLighter", isInheritedLighter_);
    }
    if (name_ != name_default_) {
        json.insert("name", name_);
    }
    if (documentation_ != documentation_default_) {
        json.insert("documentation", documentation_);
    }
    if (resolution_ != resolution_default_) {
        json.insert("resolution", resolution_);
    }
    if (bounds_) {
        QJsonObject bounds_json;
        bounds_->toJson(bounds_json);
        json.insert("bounds", bounds_json);
    }
}

/// <summary>
/// isFrame getter
/// Indicates when diagram frames shall be shown.
/// </summary>
bool UMLDiagram::isFrame() const {
    return isFrame_;
}

/// <summary>
/// isFrame setter
/// Indicates when diagram frames shall be shown.
/// </summary>
void UMLDiagram::setIsFrame(bool value) {
    isFrame_ = value;
}

/// <summary>
/// isIso getter
/// Indicate when ISO notation rules shall be followed.
/// </summary>
bool UMLDiagram::isIso() const {
    return isIso_;
}

/// <summary>
/// isIso setter
/// Indicate when ISO notation rules shall be followed.
/// </summary>
void UMLDiagram::setIsIso(bool value) {
    isIso_ = value;
}

/// <summary>
/// heading getter
/// </summary>
shared_ptr<UMLLabel> UMLDiagram::heading() const {
    return heading_;
}

/// <summary>
/// heading setter
/// </summary>
void UMLDiagram::setHeading(shared_ptr<UMLLabel> value) {
    heading_ = value;
}

/// <summary>
/// isInheritedLighter getter
/// </summary>
bool UMLDiagram::isInheritedLighter() const {
    return isInheritedLighter_;
}

/// <summary>
/// isInheritedLighter setter
/// </summary>
void UMLDiagram::setIsInheritedLighter(bool value) {
    isInheritedLighter_ = value;
}

/// <summary>
/// name getter
/// the name of the diagram.
/// </summary>
QString UMLDiagram::name() const {
    return name_;
}

/// <summary>
/// name setter
/// the name of the diagram.
/// </summary>
void UMLDiagram::setName(const QString& value) {
    name_ = value;
}

/// <summary>
/// documentation getter
/// the documentation of the diagram.
/// </summary>
QString UMLDiagram::documentation() const {
    return documentation_;
}

/// <summary>
/// documentation setter
/// the documentation of the diagram.
/// </summary>
void UMLDiagram::setDocumentation(const QString& value) {
    documentation_ = value;
}

/// <summary>
/// resolution getter
/// the resolution of the diagram expressed in user units per inch.
/// </summary>
double UMLDiagram::resolution() const {
    return resolution_;
}

/// <summary>
/// resolution setter
/// the resolution of the diagram expressed in user units per inch.
/// </summary>
void UMLDiagram::setResolution(double value) {
    resolution_ = value;
}

/// <summary>
/// bounds getter
/// the optional bounds of the shape relative to the origin of its nesting plane.
/// </summary>
shared_ptr<Bounds> UMLDiagram::bounds() const {
    return bounds_;
}

/// <summary>
/// bounds setter
/// the optional bounds of the shape relative to the origin of its nesting plane.
/// </summary>
void UMLDiagram::setBounds(shared_ptr<Bounds> value) {
    bounds_ = value;
}

} // namespace uml
